package dao;

import javax.persistence.*;

import entity.User;
import util.JpaUtil;

public class UserDao {

	EntityManager em = JpaUtil.getEntityManager();

	public User selectUserByEmailAndPassword(String username, String password) {

		Query q = em
				.createQuery("SELECT u FROM User u WHERE u.username = :username AND u.password = :password");

		q.setParameter("username", username);
		q.setParameter("password", password);

		if (q.getResultList().size() != 0) {
			return (User) q.getResultList().get(0);
		} else
			return new User();
	}
}
